abstract class Car(val carNumber: String,val carBrand: String,val carColor: String,
                   val carPrice: String) {
  def drive(): Unit = {
    println(s"${carColor}的${carBrand}正在驾驶")
  }
  def parking(): Unit = {
    println(s"${carBrand}停车中")
  }
  def oil(): Unit = {
    println(s"${carBrand}加油中")
  }
}
class ElectricCar(override val carNumber: String,
                  override val carBrand: String,
                  override val carColor: String,
                  override val carPrice: String,
                  val batteryCapacity: Int,
                  val range: Int) extends Car(carNumber, carBrand, carColor, carPrice) {
  override def drive(): Unit = {
    if (range > 0) {
      println(s"${carColor}的${carBrand}剩余续航：$range 公里")
    } else {
      println("电池续航不足，无法驾驶")
    }
  }
  // 充电方法
  def charge_battery(amount: Int): Unit = {
    println(s"正在充电，充电量为：$amount")
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val myCar = new Car("hcy123", "特斯拉", "红色", "$20,000") {}
    myCar.drive()
    println("2小时后")
    myCar.oil()
    println("------------")
    val myElectricCar = new ElectricCar("yn456", "宝马", "绿色", "$40,000", 100, 50)
    myElectricCar.drive()
    println("3小时后")
    myElectricCar.parking()
    myElectricCar.charge_battery(70)
  }
}